package com.hejjon.syyapi.util;

import com.hejjon.syyapi.bean.ConnectionInfo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by caoshi at 22:01 2021-10-12
 */
public class JDBCUtil {


    /**
     * 获取连接
     * @param connInfo
     * @return
     */
    public static Connection getConnection(ConnectionInfo connInfo) {
        Connection conn = null;
        String driver = connInfo.getDriver();
        String url = connInfo.getUrl();
        String username = connInfo.getUsername();
        String password = connInfo.getPassword();

        try {
            // 加载驱动
            Class.forName(driver);
            // 获取连接
            conn = DriverManager.getConnection(url, username, password);

        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }

        return conn;
    }


}
